package com.start.xiancheng;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


@Slf4j
public class FutureTaskDemo {


    public static void main(String[] args) throws Exception {


        /**
         * 传统写法
         */
        FutureTask<Integer> task = new FutureTask<>(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                return 123;
            }
        });

        /**
         * Lambda 语法
         */
        FutureTask<Integer> task2 = new FutureTask<Integer>(() -> {
            log.info("进入task");
            return 1;
        });


        new Thread(task2, "tt").start();

        // 带返回结果的线程
        Integer integer = task.get();


    }


}
